<template>
    <div class="contribution-rank">
        <div v-if="loading" class="loading-container">
            <div class="loading-spinner"></div>
            <span>加载中...</span>
        </div>

        <div v-else-if="contributors.length === 0" class="empty-state">
            <i class="fas fa-users-slash"></i>
            <p>暂无贡献数据</p>
        </div>

        <template v-else>
            <div class="scroll-container" ref="scrollContainer" :style="getScrollContainerStyle()">
                <div v-if="contributors.length > 5" class="scroll-indicator">
                    <i class="fas fa-chevron-down"></i>
                </div>
                <div class="rank-list-wrapper">
                    <transition-group name="rank-list" tag="ul" class="rank-list"
                        :style="{ transform: `translateY(${-currentIndex * 64}px)` }">
                        <li v-for="(contributor, index) in contributors" :key="contributor.id || index"
                            class="rank-item" :class="{
                                'top-rank': index < 3,
                                'active-item': index >= currentIndex && index < currentIndex + 5,
                                'first-rank': index === 0,
                                'second-rank': index === 1,
                                'third-rank': index === 2
                            }">
                            <div class="rank-position" :class="getRankClass(index)">{{ index + 1 }}</div>
                            <el-popover placement="right" trigger="hover" :width="280">
                                <template #reference>
                                    <el-avatar :src="contributor.avatar || defaultAvatar" class="contributor-avatar"
                                        @error="handleAvatarError"></el-avatar>
                                </template>
                                <UserProfileCard :user-id="contributor.id" />
                            </el-popover>
                            <div class="contributor-info" @click="goToUserProfile(contributor.id)">
                                <div class="contributor-name">
                                    <span>{{ contributor.nickname || '匿名用户' }}</span>
                                    <span class="badge" v-if="index < 3">{{ getRankTitle(index) }}</span>
                                </div>
                                <div class="contribution-stats">
                                    <span class="stat-item"><i class="fas fa-book-open stat-icon"></i> {{
                                        contributor.articleCount || 0 }} 篇</span>
                                    <span class="stat-item"><i class="fas fa-eye stat-icon"></i> {{
                                        formatNumber(contributor.totalViews) }}</span>
                                    <span class="stat-item"><i class="fas fa-thumbs-up stat-icon"></i> {{
                                        contributor.totalLikes || 0 }}</span>
                                </div>
                            </div>
                        </li>
                    </transition-group>
                </div>
            </div>
            <div class="scroll-controls" v-if="contributors.length > 5">
                <div class="scroll-arrows">
                    <button @click="scrollUp" :disabled="currentIndex <= 0" class="scroll-btn prev">
                        <i class="fas fa-chevron-up"></i>
                    </button>
                    <button @click="scrollDown" :disabled="currentIndex >= contributors.length - 5"
                        class="scroll-btn next">
                        <i class="fas fa-chevron-down"></i>
                    </button>
                </div>
                <div class="scroll-dots">
                    <span v-for="(_, idx) in Math.ceil(contributors.length / 5)" :key="idx"
                        :class="{ active: Math.floor(currentIndex / 5) === idx }" @click="goToPage(idx)">
                    </span>
                </div>
            </div>
        </template>
    </div>
</template>

<script>
import { getContributionRankApi } from '@/api/site'
import UserProfileCard from '@/components/UserProfileCard/index.vue';

export default {
    name: 'ContributionRank',
    components: {
        UserProfileCard
    },
    data() {
        return {
            contributors: [],
            currentIndex: 0,
            scrollInterval: null,
            manualScrollTimeout: null,
            isHovering: false,
            loading: true,
            defaultAvatar: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png',
            isScrolling: false,
            touchStartY: 0,
            touchEndY: 0,
            touchStartTime: 0,
            animationFrameId: null
        }
    },
    mounted() {
        this.fetchContributors()
    },
    beforeDestroy() {
        this.stopAutoScroll()
        clearTimeout(this.manualScrollTimeout)
        if (this.animationFrameId) {
            cancelAnimationFrame(this.animationFrameId);
        }

        // 移除事件监听器
        const container = this.$refs.scrollContainer
        if (container) {
            container.removeEventListener('mouseenter', this.stopAutoScroll)
            container.removeEventListener('mouseleave', this.startAutoScroll)
            container.removeEventListener('wheel', this.handleWheel)
            container.removeEventListener('touchstart', this.handleTouchStart)
            container.removeEventListener('touchmove', this.handleTouchMove)
            container.removeEventListener('touchend', this.handleTouchEnd)
        }
    },
    methods: {
        goToUserProfile(userId) {
            if (userId) {
                this.$router.push(`/user/${userId}`);
            }
        },
        async fetchContributors() {
            this.loading = true
            try {
                const response = await getContributionRankApi()

                if (response && response.code === 200 && response.data) {
                    // 确保每个条目都有唯一ID
                    this.contributors = response.data.map((item, idx) => {
                        return { ...item, id: item.id || `contributor-${idx}` }
                    });

                    // 在数据加载后延迟执行
                    this.$nextTick(() => {
                        // 初始化滚动事件监听
                        const container = this.$refs.scrollContainer
                        if (container) {
                            container.addEventListener('mouseenter', this.stopAutoScroll)
                            container.addEventListener('mouseleave', this.startAutoScroll)
                            container.addEventListener('wheel', this.handleWheel, { passive: false })
                            container.addEventListener('touchstart', this.handleTouchStart, { passive: true })
                            container.addEventListener('touchmove', this.handleTouchMove, { passive: false })
                            container.addEventListener('touchend', this.handleTouchEnd, { passive: true })

                            // 启动自动滚动
                            this.startAutoScroll()
                        }
                    })
                } else {
                    this.contributors = []
                }
            } catch (error) {
                this.contributors = []
            } finally {
                this.loading = false
            }
        },
        getScrollContainerStyle() {
            // 计算容器高度，每个项目64px高，但最多显示5个
            const itemCount = Math.min(5, this.contributors.length)
            const height = itemCount * 64
            return {
                height: `${height}px`
            }
        },
        handleAvatarError(e) {
            e.target.src = this.defaultAvatar
        },
        // 触摸事件处理
        handleTouchStart(event) {
            this.touchStartY = event.touches[0].clientY
            this.touchStartTime = Date.now()
            this.stopAutoScroll()
        },
        handleTouchMove(event) {
            event.preventDefault()
            this.touchEndY = event.touches[0].clientY
        },
        handleTouchEnd() {
            const touchDiff = this.touchStartY - this.touchEndY
            const timeDiff = Date.now() - this.touchStartTime

            // 检测滑动速度和方向
            if (Math.abs(touchDiff) > 30 && timeDiff < 300) {
                if (touchDiff > 0) {
                    this.smoothScroll(this.currentIndex + 1)
                } else {
                    this.smoothScroll(this.currentIndex - 1)
                }
            }

            // 3秒后恢复自动滚动
            this.manualScrollTimeout = setTimeout(() => {
                this.isHovering = false
                this.startAutoScroll()
            }, 3000)
        },
        handleWheel(event) {
            // 阻止默认滚动行为
            event.preventDefault()

            // 如果正在执行平滑滚动，则不处理新的滚动事件
            if (this.isScrolling) return

            // 根据滚动方向决定是向上还是向下滚动
            if (event.deltaY > 0) {
                this.smoothScroll(this.currentIndex + 1)
            } else {
                this.smoothScroll(this.currentIndex - 1)
            }

            // 清除之前的自动滚动
            this.stopAutoScroll()

            // 3秒后恢复自动滚动
            this.manualScrollTimeout = setTimeout(() => {
                this.isHovering = false
                this.startAutoScroll()
            }, 3000)
        },
        smoothScroll(targetIndex) {
            // 确保目标索引在有效范围内
            targetIndex = Math.max(0, Math.min(targetIndex, Math.max(0, this.contributors.length - 5)))

            if (targetIndex === this.currentIndex) return

            this.isScrolling = true

            // 设置平滑滚动的动画
            const startIndex = this.currentIndex
            const indexDiff = targetIndex - startIndex
            const duration = 400 // 滚动动画持续时间（毫秒）
            const startTime = Date.now()

            if (this.animationFrameId) {
                cancelAnimationFrame(this.animationFrameId);
            }

            const animateScroll = () => {
                const elapsedTime = Date.now() - startTime
                const progress = Math.min(elapsedTime / duration, 1)
                // 使用缓动函数使动画更自然
                const easeProgress = this.easeInOutCubic(progress)

                this.currentIndex = Math.round(startIndex + indexDiff * easeProgress)

                if (progress < 1) {
                    this.animationFrameId = requestAnimationFrame(animateScroll)
                } else {
                    this.currentIndex = targetIndex
                    this.isScrolling = false
                    this.animationFrameId = null
                }
            }

            this.animationFrameId = requestAnimationFrame(animateScroll)
        },
        easeInOutCubic(t) {
            return t < 0.5
                ? 4 * t * t * t
                : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1
        },
        getRankClass(index) {
            if (index === 0) return 'gold'
            if (index === 1) return 'silver'
            if (index === 2) return 'bronze'
            return ''
        },
        getRankTitle(index) {
            if (index === 0) return '博客达人'
            if (index === 1) return '知识专家'
            if (index === 2) return '优质创作者'
            return ''
        },
        formatNumber(num) {
            if (!num) return 0
            if (num >= 10000) {
                return (num / 10000).toFixed(1) + 'w'
            } else if (num >= 1000) {
                return (num / 1000).toFixed(1) + 'k'
            }
            return num
        },
        startAutoScroll() {
            if (this.isHovering || this.contributors.length <= 5) return

            this.scrollInterval = setInterval(() => {
                this.smoothScroll(this.currentIndex + 1)
            }, 4000) // 延长时间让用户有更多时间阅读
        },
        stopAutoScroll() {
            this.isHovering = true
            if (this.scrollInterval) {
                clearInterval(this.scrollInterval)
                this.scrollInterval = null
            }
        },
        scrollDown() {
            const maxIndex = this.contributors.length - 5
            if (this.currentIndex < maxIndex) {
                this.smoothScroll(this.currentIndex + 1)
            } else {
                this.smoothScroll(0) // 循环到顶部
            }

            // 清除之前的自动滚动
            this.stopAutoScroll()

            // 3秒后恢复自动滚动
            this.manualScrollTimeout = setTimeout(() => {
                this.isHovering = false
                this.startAutoScroll()
            }, 3000)
        },
        scrollUp() {
            if (this.currentIndex > 0) {
                this.smoothScroll(this.currentIndex - 1)
            } else {
                // 循环到底部
                this.smoothScroll(Math.max(0, this.contributors.length - 5))
            }

            // 清除之前的自动滚动
            this.stopAutoScroll()

            // 3秒后恢复自动滚动
            this.manualScrollTimeout = setTimeout(() => {
                this.isHovering = false
                this.startAutoScroll()
            }, 3000)
        },
        goToPage(pageIndex) {
            this.smoothScroll(pageIndex * 5)

            // 清除之前的自动滚动
            this.stopAutoScroll()

            // 用户手动操作后3秒恢复自动滚动
            this.manualScrollTimeout = setTimeout(() => {
                this.isHovering = false
                this.startAutoScroll()
            }, 3000)
        }
    }
}
</script>

<style lang="scss" scoped>
.contribution-rank {
    width: 100%;
    position: relative;
    z-index: 1;

    .loading-container {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 200px;

        .loading-spinner {
            width: 36px;
            height: 36px;
            border: 3px solid rgba(99, 102, 241, 0.2);
            border-top: 3px solid #6366f1;
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin-bottom: 10px;
        }

        span {
            color: var(--text-secondary);
            font-size: 0.9rem;
        }
    }

    .empty-state {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 200px;
        color: var(--text-secondary);

        i {
            font-size: 2rem;
            margin-bottom: 15px;
            opacity: 0.5;
        }

        p {
            font-size: 0.9rem;
        }
    }

    .scroll-container {
        overflow: hidden;
        position: relative;
        transition: height 0.3s ease;
        border-radius: 8px;
        margin-top: 6px;
        /* 增加顶部间距防止皇冠被切断 */

        .scroll-indicator {
            position: absolute;
            bottom: 5px;
            left: 50%;
            transform: translateX(-50%);
            width: 24px;
            height: 24px;
            border-radius: 50%;
            background: rgba(99, 102, 241, 0.8);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 2;
            box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
            animation: bounce 1.5s infinite;
            opacity: 0.8;
            transition: opacity 0.3s ease;

            &:hover {
                opacity: 1;
            }

            i {
                font-size: 0.8rem;
                animation: pulse 1.5s infinite;
            }
        }

        &:hover {
            .scroll-indicator {
                opacity: 0;
            }
        }

        .rank-list-wrapper {
            position: relative;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    }

    .rank-list {
        position: absolute;
        width: 100%;
        transition: transform 0.5s cubic-bezier(0.23, 1, 0.32, 1);
        will-change: transform;
        padding: 0;
        margin: 0;
        list-style: none;
    }

    .rank-list-enter-active,
    .rank-list-leave-active {
        transition: all 0.5s;
    }

    .rank-list-enter,
    .rank-list-leave-to {
        opacity: 0;
        transform: translateY(30px);
    }

    .rank-item {
        display: flex;
        align-items: center;
        padding: 12px;
        margin-bottom: 8px;
        border-radius: 8px;
        background: rgba(99, 102, 241, 0.03);
        height: 56px;
        transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        position: relative;
        opacity: 0.75;
        overflow: hidden;

        .contributor-info {
            cursor: pointer;
        }

        &::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0));
            transform: translateX(-100%);
            opacity: 0;
            transition: opacity 0.6s ease;
        }

        &.active-item {
            opacity: 1;
        }

        &:hover {
            transform: translateX(5px);
            background: rgba(99, 102, 241, 0.08);
            opacity: 1;

            &::before {
                animation: shine 1.5s ease-in-out;
            }

            .contributor-avatar {
                transform: scale(1.05);
            }
        }

        &.first-rank .rank-position::before {
            animation: crown-float 2s ease-in-out infinite;
        }

        &.top-rank {
            background: linear-gradient(to right, rgba(99, 102, 241, 0.05), rgba(99, 102, 241, 0.15));
            box-shadow: 0 3px 10px rgba(99, 102, 241, 0.15);
            transform: translateY(-1px);
            opacity: 1;

            &:hover {
                transform: translateY(-3px) translateX(5px);
                box-shadow: 0 5px 15px rgba(99, 102, 241, 0.25);
            }

            &:after {
                content: '';
                position: absolute;
                top: 0;
                right: 0;
                bottom: 0;
                width: 5px;
                background: linear-gradient(to bottom, #6366f1, #8b5cf6);
                border-top-right-radius: 8px;
                border-bottom-right-radius: 8px;
            }

            // 金牌样式
            &:nth-child(1) {
                background: linear-gradient(to right, rgba(251, 191, 36, 0.05), rgba(251, 191, 36, 0.2));
                box-shadow: 0 3px 12px rgba(251, 191, 36, 0.2);
                border: 1px solid rgba(251, 191, 36, 0.2);
                padding-top: 18px;
                /* 增加顶部内边距给皇冠腾出空间 */
                height: 62px;
                /* 相应增加高度 */

                &:after {
                    background: linear-gradient(to bottom, #fbbf24, #d97706);
                }

                &:hover {
                    box-shadow: 0 5px 15px rgba(251, 191, 36, 0.3);
                }

                .contributor-name .badge {
                    background: linear-gradient(135deg, #fbbf24, #d97706);
                }
            }

            // 银牌样式
            &:nth-child(2) {
                background: linear-gradient(to right, rgba(229, 231, 235, 0.1), rgba(156, 163, 175, 0.2));
                box-shadow: 0 3px 12px rgba(156, 163, 175, 0.15);
                border: 1px solid rgba(156, 163, 175, 0.15);

                &:after {
                    background: linear-gradient(to bottom, #e5e7eb, #9ca3af);
                }

                &:hover {
                    box-shadow: 0 5px 15px rgba(156, 163, 175, 0.25);
                }

                .contributor-name .badge {
                    background: linear-gradient(135deg, #e5e7eb, #9ca3af);
                    color: #1f2937;
                }
            }

            // 铜牌样式
            &:nth-child(3) {
                background: linear-gradient(to right, rgba(217, 119, 6, 0.05), rgba(217, 119, 6, 0.15));
                box-shadow: 0 3px 12px rgba(217, 119, 6, 0.15);
                border: 1px solid rgba(217, 119, 6, 0.15);

                &:after {
                    background: linear-gradient(to bottom, #d97706, #92400e);
                }

                &:hover {
                    box-shadow: 0 5px 15px rgba(217, 119, 6, 0.25);
                }

                .contributor-name .badge {
                    background: linear-gradient(135deg, #d97706, #92400e);
                }
            }
        }

        .rank-position {
            width: 24px;
            height: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            background: #a5b4fc;
            color: white;
            font-weight: bold;
            font-size: 0.8rem;
            margin-right: 12px;
            flex-shrink: 0;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;

            &.gold {
                background: linear-gradient(135deg, #fbbf24, #d97706);
                width: 28px;
                height: 28px;
                font-size: 0.9rem;
                box-shadow: 0 3px 8px rgba(251, 191, 36, 0.3);
                position: relative;
                margin-top: -14px;
                /* 调整位置，使皇冠不被遮挡 */

                &:before {
                    content: '👑';
                    position: absolute;
                    top: -16px;
                    left: -1px;
                    z-index: 10;
                    font-size: 14px;
                    transform-origin: bottom center;
                    transform: rotate(-15deg);
                    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
                }
            }

            &.silver {
                background: linear-gradient(135deg, #e5e7eb, #9ca3af);
                width: 26px;
                height: 26px;
                box-shadow: 0 3px 8px rgba(156, 163, 175, 0.3);
            }

            &.bronze {
                background: linear-gradient(135deg, #d97706, #92400e);
                width: 26px;
                height: 26px;
                box-shadow: 0 3px 8px rgba(217, 119, 6, 0.3);
            }
        }

        .contributor-avatar {
            width: 38px;
            height: 38px;
            margin-right: 12px;
            border: 2px solid white;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;

            .top-rank:nth-child(1) & {
                width: 42px;
                height: 42px;
                border: 3px solid rgba(251, 191, 36, 0.3);
                box-shadow: 0 3px 10px rgba(251, 191, 36, 0.25);
            }

            .top-rank:nth-child(2) & {
                border: 2px solid rgba(156, 163, 175, 0.3);
                box-shadow: 0 3px 8px rgba(156, 163, 175, 0.2);
            }

            .top-rank:nth-child(3) & {
                border: 2px solid rgba(217, 119, 6, 0.2);
                box-shadow: 0 3px 8px rgba(217, 119, 6, 0.2);
            }
        }

        .contributor-info {
            flex: 1;
            min-width: 0;
            display: flex;
            flex-direction: column;
            justify-content: center;

            .contributor-name {
                font-weight: 500;
                margin-bottom: 4px;
                font-size: 0.95rem;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                display: flex;
                align-items: center;
                gap: 6px;

                .badge {
                    background: linear-gradient(135deg, #6366f1, #8b5cf6);
                    color: white;
                    font-size: 0.7rem;
                    padding: 2px 6px;
                    border-radius: 4px;
                    font-weight: bold;
                    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.2);
                }
            }

            .contribution-stats {
                display: flex;
                font-size: 0.75rem;
                color: var(--text-secondary);
                gap: 10px;

                .stat-item {
                    display: flex;
                    align-items: center;
                    gap: 4px;
                    background: rgba(99, 102, 241, 0.05);
                    border-radius: 12px;
                    padding: 2px 6px;
                    transition: all 0.3s ease;
                    backdrop-filter: blur(2px);

                    &:hover {
                        background: rgba(99, 102, 241, 0.1);
                    }

                    .stat-icon {
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        font-size: 0.7rem;
                        width: 16px;
                        height: 16px;
                        border-radius: 50%;
                        color: white;

                        &.fa-book-open {
                            background: linear-gradient(135deg, #60a5fa, #3b82f6);
                        }

                        &.fa-eye {
                            background: linear-gradient(135deg, #a78bfa, #8b5cf6);
                        }

                        &.fa-thumbs-up {
                            background: linear-gradient(135deg, #f87171, #ef4444);
                        }
                    }
                }

                .top-rank:nth-child(1) & {
                    font-weight: 500;

                    .stat-item {
                        background: rgba(251, 191, 36, 0.05);

                        &:hover {
                            background: rgba(251, 191, 36, 0.1);
                        }
                    }
                }

                .top-rank:nth-child(2) & .stat-item {
                    background: rgba(156, 163, 175, 0.05);

                    &:hover {
                        background: rgba(156, 163, 175, 0.1);
                    }
                }

                .top-rank:nth-child(3) & .stat-item {
                    background: rgba(217, 119, 6, 0.05);

                    &:hover {
                        background: rgba(217, 119, 6, 0.1);
                    }
                }
            }
        }
    }

    .scroll-controls {
        margin-top: 10px;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .scroll-arrows {
            display: flex;
            gap: 8px;

            .scroll-btn {
                width: 28px;
                height: 28px;
                border-radius: 50%;
                background: rgba(99, 102, 241, 0.1);
                border: none;
                color: #6366f1;
                cursor: pointer;
                display: flex;
                align-items: center;
                justify-content: center;
                transition: all 0.2s ease;
                position: relative;
                overflow: hidden;

                &::after {
                    content: '';
                    position: absolute;
                    top: 0;
                    left: 0;
                    width: 100%;
                    height: 100%;
                    background: radial-gradient(circle, rgba(99, 102, 241, 0.2) 0%, rgba(99, 102, 241, 0) 70%);
                    opacity: 0;
                    transform: scale(0);
                    transition: transform 0.3s ease, opacity 0.3s ease;
                }

                &:hover:not(:disabled) {
                    background: rgba(99, 102, 241, 0.2);
                    transform: translateY(-2px);

                    &::after {
                        opacity: 1;
                        transform: scale(2);
                    }
                }

                &:active:not(:disabled) {
                    transform: translateY(0);
                }

                &:disabled {
                    opacity: 0.4;
                    cursor: not-allowed;
                }

                i {
                    font-size: 0.8rem;
                    position: relative;
                    z-index: 1;
                }
            }
        }

        .scroll-dots {
            display: flex;
            gap: 6px;

            span {
                width: 8px;
                height: 8px;
                border-radius: 50%;
                background: #e5e7eb;
                cursor: pointer;
                transition: all 0.3s ease;

                &.active {
                    width: 18px;
                    border-radius: 4px;
                    background: #6366f1;
                }

                &:hover:not(.active) {
                    background: #c7d2fe;
                    transform: scale(1.2);
                }
            }
        }
    }
}

@keyframes shine {
    0% {
        opacity: 0;
        transform: translateX(-100%);
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 0;
        transform: translateX(100%);
    }
}

@keyframes crown-float {

    0%,
    100% {
        transform: rotate(-15deg);
    }

    50% {
        transform: rotate(5deg);
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes bounce {

    0%,
    100% {
        transform: translateX(-50%) translateY(0);
    }

    50% {
        transform: translateX(-50%) translateY(-5px);
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }
}

// 暗色主题适配
@media (prefers-color-scheme: dark) {
    .contribution-rank {
        .rank-item {
            background: rgba(255, 255, 255, 0.03);

            &:hover {
                background: rgba(255, 255, 255, 0.08);
            }

            &.top-rank {
                background: linear-gradient(to right, rgba(99, 102, 241, 0.1), rgba(99, 102, 241, 0.2));
            }

            .contributor-avatar {
                border-color: #1f2937;
            }

            .contribution-stats .stat-item {
                background: rgba(255, 255, 255, 0.05);

                &:hover {
                    background: rgba(255, 255, 255, 0.1);
                }
            }

            &::before {
                background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0));
            }
        }

        .scroll-controls {
            .scroll-dots span {
                background: #4b5563;

                &.active {
                    background: #818cf8;
                }

                &:hover:not(.active) {
                    background: #6b7280;
                }
            }

            .scroll-arrows .scroll-btn {
                background: rgba(99, 102, 241, 0.15);
                color: #818cf8;

                &:hover:not(:disabled) {
                    background: rgba(99, 102, 241, 0.25);
                }

                &::after {
                    background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, rgba(99, 102, 241, 0) 70%);
                }
            }
        }

        .scroll-container .scroll-indicator {
            background: rgba(99, 102, 241, 0.6);
            box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
        }
    }
}
</style>